// pages/showOrbit/showOrbit.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    markers: [
      
    ],
    empty:true,
    my:{},
    sufferer:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var myId = options.id;
    that.setData({
      empty:true,
      markers:[],
    });
    wx.cloud.callFunction({
      name: 'showOrbit',
      data: {
        id: myId,
      },
      success: function (res) {
        console.log(res.result)
        if(res.result.empty){
          that.setData({
            empty:true,
            markers:[],
          })
        }
        else{
          var my = res.result.my;
          var markers =[]
          myMarker ={
            id:0,
            latitude:my.location.coordinates[1],
            longitude:my.location.coordinates[0],
            iconPath:"/images/mark1.png",
            callout	:{
              content:"我",
              color:"#fff",
              bgColor:"#0081ff",
              display:'ALWAYS',
              borderRadius:5,
              padding:3,
            }
          }
          var markers =[];
          markers.push(myMarker);
          let sufferer = res.result.sufferer;
          
          for (let i in sufferer){
            var s = {
              id:i*1+1,
            latitude:sufferer[i].location.coordinates[1],
            longitude:sufferer[i].location.coordinates[0],
            iconPath:"/images/mark2.png",
            callout	:{
              content:"患者 "+sufferer[i].name,
              color:"#fff",
              bgColor:"#e54d42",
              display:'ALWAYS',
              borderRadius:5,
              padding:3,
            }
            }
            markers.push(s);
          }
          that.setData({
            empty:false,
            lat:my.location.coordinates[1],
            lng:my.location.coordinates[0],
            markers:markers,
            my:my,
            sufferer:sufferer
          })
        }
      },
      fail: err => {
        console.log(err);
      }
    });
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title:"疫轨迹，了解感染者出行活动，发现自身感染风险",
      imageUrl:"/images/share.png",
      path:"/pages/sufferer/travel/travel",
    }
  },

  copyText: function (e) {
    wx.setClipboardData({
      data: e.currentTarget.dataset.text,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              icon: 'none',
              title: '复制成功,请到浏览器查看信息源'
            })
          }
        })
      }
    })
  },



})